package com.zian.controller.user;


import com.zian.common.R;
import com.zian.domain.dto.PageDTO;
import com.zian.domain.dto.ShoppingDTO;
import com.zian.domain.query.PageQuery;
import com.zian.domain.vo.ShoppingQueryVO;
import com.zian.service.ISysShoppingCartItemService;
import com.zian.validation.ValidGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2024-09-08
 */
@Slf4j
@Api(tags = "购物车管理")
@RestController
@RequestMapping("/user/shopping")
@RequiredArgsConstructor
public class SysShoppingCartItemController {

    private final ISysShoppingCartItemService shoppingCartItemService;

    @PostMapping("/{goodsId}")
   @ApiOperation("添加购物车")
    public R addShoppingCartItem(@PathVariable Long goodsId) {
        shoppingCartItemService.addShoppingCartItem(goodsId);
        return R.ok();
    }

    @DeleteMapping("/{id}")
   @ApiOperation("删除购物车")
    public R deleteShoppingCartItem(@PathVariable Long id) {
        shoppingCartItemService.deleteShoppingCartItem(id);
        return R.ok();
    }

    @PutMapping
   @ApiOperation("修改购物车")
    public R updateGoodsCount(@RequestBody @Validated(ValidGroup.Crud.Update.class) ShoppingDTO dto) {
        shoppingCartItemService.updateGoodsCount(dto);
        return R.ok();
    }

    @GetMapping
   @ApiOperation("获取购物车列表")
    public R<List<ShoppingQueryVO>> getShoppingCartItemList() {
        List<ShoppingQueryVO> vo = shoppingCartItemService.getShoppingCartItemList();
        return R.ok(vo);
    }

    @GetMapping("/count")
   @ApiOperation("获取购物车数量")
    public R<Integer> getShoppingCartItemCount() {
        Integer count = shoppingCartItemService.getShoppingCartItemCount();
        return R.ok(count);
    }

    @GetMapping("/selected")
   @ApiOperation("获取以选择的购物项")
    public R<List<ShoppingQueryVO>> getSelectedItems(@RequestParam("ids") List<Long> ids) {
        log.info("查询以选择的购物项：{}", ids);
        List<ShoppingQueryVO> vos = shoppingCartItemService.getSelectedItems(ids);
        return R.ok(vos);
    }
}
